package com.wingsoft.basic.controller;

import com.wingsoft.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import com.github.pagehelper.Page;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wingsoft.common.annotation.Log;
import com.wingsoft.common.core.controller.BaseController;
import com.wingsoft.common.core.domain.AjaxResult;
import com.wingsoft.common.enums.BusinessType;
import com.wingsoft.basic.domain.CaseInfo;
import com.wingsoft.basic.dto.CaseInfoDto;
import com.wingsoft.basic.vo.CaseInfoVo;
import com.wingsoft.basic.service.impl.CaseInfoServiceImpl;
import com.wingsoft.common.utils.poi.ExcelUtil;

/**
 * 案例Controller
 *
 * @author hemj
 * @date 2025-10-25
 */
@Api(tags = "案例接口")
@RestController
@RequestMapping("/basic/caseInfo")
public class CaseInfoController extends BaseController
{
    @Autowired
    private CaseInfoServiceImpl caseInfoService;

    /**
     * 统计数量案例
     */
    @PreAuthorize("@ss.hasPermi('basic:caseInfo:list')")
    @PostMapping("/count")
    @ApiOperation("统计数量案例")
    public R<Long> count(@RequestBody CaseInfoDto caseInfoDto)
    {
        Long num = caseInfoService.countList(caseInfoDto);
        return R.ok(num);
    }

    /**
     * 分页查询案例
     */
    //@PreAuthorize("@ss.hasPermi('basic:caseInfo:list')")
    @PostMapping("/list")
    @ApiOperation("分页查询案例")
    public R<List<CaseInfoVo>> list(@RequestBody CaseInfoDto caseInfoDto)
    {
        Page page = startPage();
        List<CaseInfoVo> list = caseInfoService.queryList(caseInfoDto);
        return getResDataTable(list,page);
    }

    /**
     * 查询案例列表
     */
    //@PreAuthorize("@ss.hasPermi('basic:caseInfo:list')")
    @PostMapping("/query")
    @ApiOperation("查询案例列表")
    public R<List<CaseInfoVo>> query(@RequestBody CaseInfoDto caseInfoDto)
    {
        List<CaseInfoVo> list = caseInfoService.queryList(caseInfoDto);
        return R.ok(list);
    }

    /**
     * 导出案例
     */
    @PreAuthorize("@ss.hasPermi('basic:caseInfo:export')")
    @Log(title = "导出案例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出案例")
    public void export(HttpServletResponse response, CaseInfoDto caseInfoDto)
    {
        List<CaseInfoVo> list = caseInfoService.queryList(caseInfoDto);
        ExcelUtil<CaseInfoVo> util = new ExcelUtil<CaseInfoVo>(CaseInfoVo.class);
        util.exportExcel(response, list, "案例数据");
    }

    /**
     * 获取案例详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:caseInfo:query')")
    @PostMapping(value = "/get")
    @ApiOperation("获取案例详细信息")
    public R<CaseInfoVo> getInfo(@RequestBody CaseInfoDto caseInfoDto)
    {
        return R.ok(caseInfoService.getOneById(caseInfoDto.getId()));
    }

    /**
     * 新增案例
     */
    @PreAuthorize("@ss.hasPermi('basic:caseInfo:add')")
    @Log(title = "新增案例", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    @ApiOperation("新增案例")
    public R add(@RequestBody CaseInfoDto caseInfoDto)
    {
        return R.ok(caseInfoService.saveCascade(caseInfoDto));
    }

    /**
     * 修改案例
     */
    @PreAuthorize("@ss.hasPermi('basic:caseInfo:edit')")
    @Log(title = "修改案例", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update")
    @ApiOperation("修改案例")
    public R edit(@RequestBody CaseInfoDto caseInfoDto)
    {
        return R.ok(caseInfoService.updateCascade(caseInfoDto));
    }

    /**
     * 删除案例
     */
    @PreAuthorize("@ss.hasPermi('basic:caseInfo:remove')")
    @Log(title = "删除案例", businessType = BusinessType.DELETE)
	@PostMapping("/delete/{ids}")
    @ApiOperation("删除案例")
    public R remove(@PathVariable Long[] ids)
    {
        caseInfoService.removeByIdList(Arrays.asList(ids));
        return R.ok();
    }
}
